package Objects;

import Utils.GameInformation;
import Utils.GameUtils;
import Utils.SoundManager;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import Objects.CQuadTree;

enum PrinnyState {
	Jump_Up_Left,		// 0 
	Jump_Down_Left,		// 1
	Jump_Up_Right,		// 2
	Jump_Down_Right,	// 3
	Move_Left,			// 4
	Move_Right,			// 5
	Stand_Left,			// 6
	Stand_Right,		// 7
	Shoot_Left,			// 8
	Shoot_Right,		// 9
	Stop_Left,			// 10
	Stop_Right,			// 11
} 



public class CPrinny {
	// Enum
	public enum PrinnyGeneralState {
		Stand, // 0
		Jump, // 1,
		Shoot, // 2
		Move // 3
	}
	/*******************************************
	 				SINGLETON
	 *******************************************/
	private static CPrinny instance = null;
	public static CPrinny getInstance() {
		if(instance == null) {
			instance = new CPrinny();
		}
		return instance;
	}
	
	/*******************************************
				VARIABLES
	 *******************************************/
	InputProcessor mInputP;
	SpriteBatch mSpriteBatch;
	private int mPrinnySizeTile = 54;
	private float mCurrentPos_X = 0;
	private float mCurrentPos_Y = 0;
	private int normalState;
	private Boolean mIsJump = false;
	private Boolean mIsRight = false;
	private int mLife = 2;
	private float mVx = 0;
	private float mVy = 0;
	private Boolean hasFraction;
	private Boolean alreadyJumped;
	
	// Public variables
	public OrthographicCamera camera;
	public CObjectsList mListObjects;
	public int generalState;
	public float x_save;
	public float y_save;
	public float friction = 0.9f;
	public float velocityX = 0.5f;
	public float velocityY = 0.5f;
	public float accY = 10f;
	public float vJump = 10;
	public float vXMax = 3;
	public int mHeal;
	Sound mSoundJump;
	/*******************************************
					CONSTRUCTOR
	 *******************************************/
	public CPrinny() {
		// TODO Auto-generated constructor stub
		mListObjects = new CObjectsList();
		mIsJump = false;
		mSoundJump = SoundManager.getInstance().getSoundJump();
	}
	
	public CPrinny(InputProcessor inputP, float x, float y) {
		this.mCurrentPos_X = x;
		this.mCurrentPos_Y = y;
//		this.mInputP = inputP;
		mSpriteBatch = new SpriteBatch();
	}
	
	
	/*******************************************
				METHODS
	 *******************************************/
	public void setSpriteBatch(SpriteBatch spriteBatch) {
		this.mSpriteBatch = spriteBatch;
	}
	
	public void setInputHandler(InputProcessor input) {
//		mInputP = input;
	}
	
	// Get width
	public float getWidth() {
		return mSpriteToDraw.getWidth();
	}
	
	// Get height
	public float getHeight() {
		return mSpriteToDraw.getHeight();
	}
	
	// Set position
	public void setPosition(float x, float y) {
		mCurrentPos_X = x;
		mCurrentPos_Y = y;
	}
	
	// Get Position
		public Vector2 getPosition() {
			return new Vector2(mCurrentPos_X, mCurrentPos_Y);
		}
		
	public Boolean isRight() {
		return mIsRight;
	}
	
	public void setIsRight(Boolean right) {
		mIsRight = right;
	}
	
	public void setJump(Boolean isJump) {
		mIsJump = isJump;
	}
	
	// Prinny is jumping ?
	public Boolean isJump() {
		return mIsJump;
	}
	
	// out of life
	public int getLife() {
		return mLife;
	}
	
	
	
	// set full life
	public void setFullLife(int life) {
		mLife = life;
	}
	
	// Set Input Processor
	public void setInputProcessor(InputProcessor inputP) {
//		this.mInputP = inputP;
	}
	
	/*************************************
	 				SPRITE
	 *************************************/
	private Sprite mSpriteToDraw;
	// Init All Sprite
	public void initSprites() {
		TextureAtlas mTextureAtlas = new TextureAtlas("Prinny_Output/prinny.atlas");
		mSpriteWalking = mTextureAtlas.createSprites("move_left");
		mSpriteWalkingRight = mTextureAtlas.createSprites("move_right");
		for(int i = 0; i < mSpriteWalking.size; i++) {
			mSpriteWalking.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteWalking.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		
		for (int i = 0; i < mSpriteWalkingRight.size; i++ ){
			mSpriteWalkingRight.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteWalkingRight.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		// Cut
		mSpriteCut = mTextureAtlas.createSprites("shoot_left");
		for (int i = 0; i < mSpriteCut.size; i++ ){
			mSpriteCut.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteCut.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		mSpriteCutRight = mTextureAtlas.createSprites("shoot_right");
		for (int i = 0; i < mSpriteCutRight.size; i++ ){
			mSpriteCutRight.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteCutRight.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		// Stand
		mSpriteStand = mTextureAtlas.createSprites("stand_left");
		for (int i = 0; i < mSpriteStand.size; i++ ){
			mSpriteStand.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteStand.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		mSpriteStandRight = mTextureAtlas.createSprites("stand_right");
		for (int i = 0; i < mSpriteStandRight.size; i++ ){
			mSpriteStandRight.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteStandRight.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		// Jump Down
		mSpriteJumpDown = mTextureAtlas.createSprites("jump_down_left");
		for (int i = 0; i < mSpriteJumpDown.size; i++ ){
			mSpriteJumpDown.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteJumpDown.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		mSpriteJumpDownRight = mTextureAtlas.createSprites("jump_down_right");
		for (int i = 0; i < mSpriteJumpDownRight.size; i++ ){
			mSpriteJumpDownRight.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteJumpDownRight.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		// Jump Up
		mSpriteJumpUp = mTextureAtlas.createSprites("jump_up_left");
		for (int i = 0; i < mSpriteJumpUp.size; i++ ){
			mSpriteJumpUp.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteJumpUp.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		mSpriteJumpUpRight = mTextureAtlas.createSprites("jump_up_right");
		for (int i = 0; i < mSpriteJumpUpRight.size; i++ ){
			mSpriteJumpUpRight.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteJumpUpRight.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		// Stop
		mSpriteStop = mTextureAtlas.createSprites("stop_left");
		for (int i = 0; i < mSpriteStop.size; i++ ){
			mSpriteStop.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteStop.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		mSpriteStopRight = mTextureAtlas.createSprites("stop_right");
		for (int i = 0; i < mSpriteStopRight.size; i++ ){
			mSpriteStopRight.get(i).setSize(mPrinnySizeTile, mPrinnySizeTile);
			mSpriteStopRight.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		
		// Death
		TextureAtlas altasDie = new TextureAtlas(Gdx.files.internal("Images/Prinny/die.atlas"));
		mSpriteDeath = altasDie.createSprites("die-left");
		for (int i = 0; i < mSpriteDeath.size; i++) {
			mSpriteDeath.get(i).setSize(60, 70);
			mSpriteDeath.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
		mSpriteDeathRight = altasDie.createSprites("die-right");
		for (int i = 0; i < mSpriteDeathRight.size; i++) {
			mSpriteDeathRight.get(i).setSize(60, 70);
			mSpriteDeathRight.get(i).setPosition(mCurrentPos_X, mCurrentPos_Y);
		}
	}
	
	// Update sprite position
	private void updateSpritePosition() {
		mSpriteToDraw.setPosition(mCurrentPos_X, mCurrentPos_Y);

	}
	/////////////////////
	// Sprite Stand
	/////////////////////
	Array<Sprite> mSpriteStand;
	Array<Sprite> mSpriteStandRight;
	int mSpriteStand_currentFrame = 0;
	float mSpriteStand_animationElapsed = 0;
	float mSpriteStand_maxTime = 0.1f;
	
	public void updateSpriteStand(float dt) {
		hasFraction = true;
		mSpriteStand_animationElapsed += dt;
		while(mSpriteStand_animationElapsed > mSpriteStand_maxTime) {
			mSpriteStand_animationElapsed -= mSpriteStand_maxTime;
			if(isRight()) {
				mSpriteStand_currentFrame = (mSpriteStand_currentFrame == mSpriteStandRight.size - 1) ? 0 : ++mSpriteStand_currentFrame;
				mSpriteToDraw = mSpriteStandRight.get(mSpriteStand_currentFrame);
			} else {
				mSpriteStand_currentFrame = (mSpriteStand_currentFrame == mSpriteStand.size - 1) ? 0 : ++mSpriteStand_currentFrame;
				mSpriteToDraw = mSpriteStand.get(mSpriteStand_currentFrame);
			}
			updateSpritePosition();
		}
	}
	
	/////////////////////
	// Sprite Walking
	/////////////////////
	Array<Sprite> mSpriteWalking;
	Array<Sprite> mSpriteWalkingRight;
	float mSpriteWalking_animationElapsed = 0;
	int mSpriteWalking_currentFrame = 0;
	float mSpriteWalking_maxTime = 0.08f;
	public void updateSpriteWalking(float dt) {
		hasFraction = true;
		mSpriteWalking_animationElapsed += dt;
		while(mSpriteWalking_animationElapsed > mSpriteWalking_maxTime) {
			mSpriteWalking_animationElapsed -= mSpriteWalking_maxTime;
			if(isRight()) {
				mSpriteWalking_currentFrame = (mSpriteWalking_currentFrame == mSpriteWalkingRight.size - 1) ? 0 : ++mSpriteWalking_currentFrame;
				mSpriteToDraw = mSpriteWalkingRight.get(mSpriteWalking_currentFrame);
			} else {
				mSpriteWalking_currentFrame = (mSpriteWalking_currentFrame == mSpriteWalking.size - 1) ? 0 : ++mSpriteWalking_currentFrame;
				mSpriteToDraw = mSpriteWalking.get(mSpriteWalking_currentFrame);
			}
			updateSpritePosition();
		}
	}
	
	/////////////////////
	// Sprite Cut
	/////////////////////
	Array<Sprite> mSpriteCut;
	Array<Sprite> mSpriteCutRight;
	float mSpriteCut_animationElapsed = 0;
	int mSpriteCut_currentFrame = 0;
	float mSpriteCut_maxTime = 0.05f;
	public void updateSpriteCut(float dt) {
		mSpriteCut_animationElapsed += dt;
		while(mSpriteCut_animationElapsed > mSpriteCut_maxTime) {
			mSpriteCut_animationElapsed -= mSpriteCut_maxTime;
			if(isRight()) {
				mSpriteCut_currentFrame = (mSpriteCut_currentFrame == mSpriteCutRight.size - 1) ? 0 : ++mSpriteCut_currentFrame;
				mSpriteToDraw = mSpriteCutRight.get(mSpriteCut_currentFrame);
			} else {
				mSpriteCut_currentFrame = (mSpriteCut_currentFrame == mSpriteCut.size - 1) ? 0 : ++mSpriteCut_currentFrame;
				mSpriteToDraw = mSpriteCut.get(mSpriteCut_currentFrame);
			}
			updateSpritePosition();
		}
		if(mSpriteCut_currentFrame == 6) {
			mSpriteCut_currentFrame = 0;
			generalState = PrinnyGeneralState.Stand.ordinal();
		}
	}
	
	/////////////////////
	// Sprite Jump
	/////////////////////
	Array<Sprite> mSpriteJumpUp;
	Array<Sprite> mSpriteJumpUpRight;
	float mSpriteJumpUp_animationElapsed = 0;
	int mSpriteJumpUp_currentFrame = 0;
	float mSpriteJumpUp_maxTime = 0.1f;
	public void updateSpriteJumpUp(float dt) {
		hasFraction = false;
		mSpriteJumpUp_animationElapsed += dt;
		while(mSpriteJumpUp_animationElapsed > mSpriteJumpUp_maxTime) {
			mSpriteJumpUp_animationElapsed -= mSpriteJumpUp_maxTime;
			if(isRight()) {
				mSpriteJumpUp_currentFrame = (mSpriteJumpUp_currentFrame == mSpriteJumpUpRight.size - 1) ? 0 : ++mSpriteJumpUp_currentFrame;
				mSpriteToDraw = mSpriteJumpUpRight.get(mSpriteJumpUp_currentFrame);
			} else {
				mSpriteJumpUp_currentFrame = (mSpriteJumpUp_currentFrame == mSpriteJumpUp.size - 1) ? 0 : ++mSpriteJumpUp_currentFrame;
				mSpriteToDraw = mSpriteJumpUp.get(mSpriteJumpUp_currentFrame);
			}
			updateSpritePosition();
		}
		if(mSpriteJumpUp_currentFrame == mSpriteJumpUp.size - 1) {
			mSpriteJumpUp_currentFrame = 0;
		}
	}
	
	/////////////////////
	// Sprite Jump Down
	/////////////////////
	Array<Sprite> mSpriteJumpDown;
	Array<Sprite> mSpriteJumpDownRight;
	float mSpriteJumpDown_animationElapsed = 0;
	int mSpriteJumpDown_currentFrame = 0;
	float mSpriteJumpDown_maxTime = 0.1f;
	public void updateSpriteJumpDown(float dt) {
		hasFraction = false;
		mSpriteJumpDown_animationElapsed += dt;
		while(mSpriteJumpDown_animationElapsed > mSpriteJumpDown_maxTime) {
			mSpriteJumpDown_animationElapsed -= mSpriteJumpDown_maxTime;
			if(isRight()) {
				mSpriteJumpDown_currentFrame = (mSpriteJumpDown_currentFrame == mSpriteJumpDownRight.size - 1) ? 0 : ++mSpriteJumpDown_currentFrame;
				mSpriteToDraw = mSpriteJumpDownRight.get(mSpriteJumpDown_currentFrame);
			} else {
				mSpriteJumpDown_currentFrame = (mSpriteJumpDown_currentFrame == mSpriteJumpDown.size - 1) ? 0 : ++mSpriteJumpDown_currentFrame;
				mSpriteToDraw = mSpriteJumpDown.get(mSpriteJumpDown_currentFrame);
			}
			updateSpritePosition();
		}
		
		updateSpriteStand(dt);
	}
	/////////////////////
	// Sprite Death
	/////////////////////	
	Array<Sprite> mSpriteDeath;
	Array<Sprite> mSpriteDeathRight;
	float mSpriteDeath_animationElapsed = 0;
	int mSpriteDeath_currentFrame = 0;
	float mSpriteDeath_maxTime = 0.2f;
	public void updateSpriteDeath(float dt) {
		hasFraction = false;
		mSpriteDeath_animationElapsed += dt;
		while(mSpriteDeath_animationElapsed > mSpriteDeath_maxTime) {
			mSpriteDeath_animationElapsed -= mSpriteDeath_maxTime;
			if(isRight()) {
				mSpriteDeath_currentFrame = (mSpriteDeath_currentFrame == mSpriteDeathRight.size - 1) ? 0 : ++mSpriteDeath_currentFrame;
				mSpriteToDraw = mSpriteDeathRight.get(mSpriteDeath_currentFrame);
			} else {
				mSpriteDeath_currentFrame = (mSpriteDeath_currentFrame == mSpriteDeath.size - 1) ? 0 : ++mSpriteDeath_currentFrame;
				mSpriteToDraw = mSpriteDeath.get(mSpriteDeath_currentFrame);
			}
			updateSpritePosition();
		}
	}
	
	/////////////////////
	// Sprite Stop
	/////////////////////
	Array<Sprite> mSpriteStop;
	Array<Sprite> mSpriteStopRight;
	float mSpriteStop_animationElapsed = 0;
	int mSpriteStop_currentFrame = 0;
	float mSpriteStop_maxTime = 0.2f;
	public void updateSpriteStop(float dt) {
		hasFraction = true;
		mSpriteStop_animationElapsed += dt;
		while(mSpriteStop_animationElapsed > mSpriteStop_maxTime) {
			mSpriteStop_animationElapsed -= mSpriteStop_maxTime;
			if(isRight()) {
				mSpriteStop_currentFrame = (mSpriteStop_currentFrame == mSpriteStopRight.size - 1) ? 0 : ++mSpriteStop_currentFrame;
				mSpriteToDraw = mSpriteStopRight.get(mSpriteStop_currentFrame);
			} else {
				mSpriteStop_currentFrame = (mSpriteStop_currentFrame == mSpriteStop.size - 1) ? 0 : ++mSpriteStop_currentFrame;
				mSpriteToDraw = mSpriteStop.get(mSpriteStop_currentFrame);
			}
			updateSpritePosition();
		} 
	}
	
	public void drawPrinny(float dt, SpriteBatch batch, CQuadTree quadtree) {
		
		if(generalState == PrinnyGeneralState.Stand.ordinal()) {
			this.updateSpriteStand(dt);
		} else if(generalState == PrinnyGeneralState.Jump.ordinal()) {
			this.updateSpriteJumpUp(dt);
		} else if(generalState == PrinnyGeneralState.Move.ordinal()) {
			this.updateSpriteWalking(dt);
		} else if(generalState == PrinnyGeneralState.Shoot.ordinal()) {
			this.updateSpriteCut(dt);
		}
		mSpriteToDraw.draw(batch);
		
//		update(dt, quadtree);
		
	}
	
	
	public void move(float dt) {
		Boolean haveFraction = hasFraction;
		if(haveFraction) {
			mVx = mVx*friction;
		}
		
		if(Gdx.input.isKeyPressed(Keys.LEFT)) {
			mIsRight = false;
			moveLeft(dt);
			generalState = PrinnyGeneralState.Move.ordinal();
			
		} else {
			
		}
		if(Gdx.input.isKeyPressed(Keys.RIGHT)) {
			mIsRight = true;
			moveRight(dt);
			generalState = PrinnyGeneralState.Move.ordinal();
		}
	}
	
	
	private float x_before;
	private float y_before;
	public int update(float dt, CQuadTree quadtree) {
		float giaTocX = GameInformation.getInstance().getPrinnyAccelerationX();
		float giaTocY = GameInformation.getInstance().getPrinnyAccelerationY();
		if(mLife == 0) {
			return 2;
		}
		float width = mSpriteToDraw.getWidth();
		float height = mSpriteToDraw.getHeight();
		move(dt);
//		PrinnyCut(keys,last_keys,m_quadTree);
		mListObjects.resetListObjects();
		quadtree.setObjectsList(mListObjects, new CRect(mCurrentPos_X, mCurrentPos_Y, mSpriteToDraw.getWidth(), mSpriteToDraw.getWidth()));
		if(CQuadTree.checkRectCollideWithList(new CRect((mCurrentPos_X+mVx),(mCurrentPos_Y+mVy), width, height), mListObjects)) {
			mIsJump = true;
			if(!CQuadTree.checkRectCollideWithList(new CRect(mCurrentPos_X, mCurrentPos_Y + mVy, width, height), mListObjects)) {
				if(Gdx.input.isKeyPressed(Keys.UP)) {
					mSoundJump.play();
					jump(dt);
				} else {
					mVx = 0;
					mVy = (float) (vJump*0.5);
					generalState = PrinnyGeneralState.Stand.ordinal();
				}
			} else {
				if(!CQuadTree.checkRectCollideWithList(new CRect(mCurrentPos_X + mVx, mCurrentPos_Y, width, height), mListObjects)) {  // va cham tren duoi'
					if(mVy > 0) { 
						// Va cham tren
						if(mInputP.keyDown(Keys.UP)) {
							mSoundJump.play();
							mVy = -vJump;
							generalState = PrinnyGeneralState.Jump.ordinal();
						} else {
							mVy = 0;
							generalState = PrinnyGeneralState.Stand.ordinal();
						}
					} else {
						// Va cham duoi
						mVy = 0;
						mIsJump = false;
					}
				} else {
					if(mInputP.keyDown(Keys.UP)) {
						mSoundJump.play();
						jump(dt);
					} else {
						mVx = 0;
						mVy = 0;
					}
				}
			}
		} else {
			generalState = PrinnyGeneralState.Jump.ordinal();
			if(mInputP.keyDown(Keys.UP) && mIsJump == true) {
				mSoundJump.play();
				mVy = -vJump;
				mIsJump = false;
			}
		}
		///////////////////////
		if (mVx < giaTocX && mVx > -giaTocX)
		{
			mVx = 0;
		}
		if (mVy < giaTocY && mVy > -giaTocY)
		{
			mVy = 0;
		}
		if(mCurrentPos_Y+height+10 > 1100)
		{
			death(dt);
		}
		/////////////////
		if(!CQuadTree.checkRectCollideWithList(new CRect(mCurrentPos_X + mVx, mCurrentPos_Y + mVy, width, height), mListObjects)) {
			if(CRect.checkStayInsideAnotherRect(new CRect(mCurrentPos_X + mVx, mCurrentPos_Y + mVy, width, height), quadtree.m_root.m_rect)) {
				x_before = mCurrentPos_X;
				y_before = mCurrentPos_Y;
				mCurrentPos_X += mVx;
				mCurrentPos_Y += mVy;
			} else {
				if(!CRect.checkStayInsideAnotherRect(new CRect(mCurrentPos_X + mVx, mCurrentPos_Y, width, height), quadtree.m_root.m_rect)) {
					mVx = 0;
				} 
				
				if(!CRect.checkStayInsideAnotherRect(new CRect(mCurrentPos_X, mCurrentPos_Y + mVy, width, height), quadtree.m_root.m_rect)) {
					mVy = 0;
				} 
				
				mCurrentPos_X += mVx;
				mCurrentPos_Y += mVy;
			}
		} else {
			if(CQuadTree.checkRectCollideWithList(new CRect(x_before,y_before,width,height), mListObjects)) {
				death(dt);
			} else {
				mCurrentPos_X = x_before;
				mCurrentPos_Y = y_before;
				mVx = 0;
				mVy = 0;
			}
		}
		// Update sprite
		/////////////
		CObject obj_check = CQuadTree.objectCheckRectWithListCheckItems(new CRect(mCurrentPos_X,mCurrentPos_Y+1,width,height), mListObjects);
		if(obj_check != null) {
			char style = obj_check.m_style;
			if(style == GameInformation.getInstance().getUnit_Monster1() || 
				style == GameInformation.getInstance().getUnit_Monster2() || 
				style == GameInformation.getInstance().getUnit_Monster3() ||
				style == GameInformation.getInstance().getUnit_Fire1() || 
				style == GameInformation.getInstance().getUnit_Trap()) {
				death(dt);
			}
			
			if(style == GameInformation.getInstance().getUnit_Save()) {
				obj_check.m_health = 0;
				x_save = obj_check.m_rect.getLeft();
				y_save = obj_check.m_rect.getTop();
				return 4;
			}
			
			if(style == GameInformation.getInstance().getUnit_End()) {
				return 1;
			}
		}
		return 0;
	}
	
	private void moveRight(float dt) {
		if(mVx < vXMax) {
			mVx += velocityX;
		}  else {
			mVx = vXMax;
		}
		mCurrentPos_X += mVx;
		
//		GameUtils.printLog("MOVE RIGHT X", " " + mCurrentPos_X);
		handleMove();
	}
	
	private void moveLeft(float dt) {
		if(mVx > - vXMax) {
			mVx -= velocityX;
		} else {
			mVx = -vXMax;
		}
		mCurrentPos_X += mVx;
		handleMove();
	}
	
	private void handleMove() {
		mSpriteToDraw.setPosition(mCurrentPos_X, mCurrentPos_Y);
	}
	
	public void jump(float delta) {
//		if(mIsJump == false) {
//			accY = 10;
//			velocityY = 100;
//			mIsJump = true;
//			mSpriteBatch.begin();
//			do {
//				if(mIsJump == true) {
//					if(velocityY > -100) {
//						velocityY -= accY;
//						mCurrentPos_Y += velocityY;
//						updateSpritePosition();
//						mSpriteToDraw.draw(mSpriteBatch);
//						GameUtils.printLog("X:" + mCurrentPos_X, "Y: " + mCurrentPos_Y);
//					}
//				}
//			} while (mCurrentPos_Y > 0);
//			
//			if(mCurrentPos_Y <= 0) {
//				velocityY = 0;
//				mIsJump = false;
//			}
//
//			updateSpritePosition();
//			mSpriteToDraw.draw(mSpriteBatch);
//			mSpriteBatch.end();
//			GameUtils.printLog("X:" + mCurrentPos_X, "Y: " + mCurrentPos_Y);
////			float width = mSpriteToDraw.getWidth();
////			float height = mSpriteToDraw.getHeight();
////			Boolean collisionLeft = CQuadTree.checkRectCollideWithList(new CRect(mCurrentPos_X - vJump, mCurrentPos_Y - vJump, width, height), mListObjects);
////			Boolean collisionRight =  CQuadTree.checkRectCollideWithList(new CRect(mCurrentPos_X + vJump, mCurrentPos_Y - vJump, width, height), mListObjects);
////			if(collisionLeft == true && collisionRight == false) {
////				mVx = vJump*0.4f;
////			}
////			if(collisionLeft == false && collisionRight == true) {
////				mVx = -vJump*0.4f;
////			}
////			mVy = -vJump;
//			
////			if(alreadyJumped == true) {
////				
////			} else {
////				mVy += vJump*0.5f;
////			}
//		}
		if(mIsJump == false) {
			velocityY = 100;
			mIsJump = true;
		}		
		do {
			if(velocityY > -100) {
				mCurrentPos_Y += velocityY;
				velocityY -= 10;
				updateSpritePosition();
				GameUtils.printLog("POSITION", "Y: " + mCurrentPos_Y);
				GameUtils.printLog("VELOCITY Y", "" + velocityY);
			} else {
				mIsJump = false;
			}
		} while (mIsJump == true);
	}
	
	public void death(float dt) {
		
	}
	
}
